package com.headwind.logistics.carrier.service.impl;

import com.headwind.logistics.carrier.dto.CarAndCarTypeAndTansportUserDto;
import com.headwind.logistics.carrier.mapper.CarAndCarTypeAndTansportUserMapper;

import com.headwind.logistics.carrier.service.inter.CarAndCarTypeAndTansportUserServiceInter;
import com.headwind.logistics.common.pojo.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author QT
 * @Date 2020/7/17 15:56
 * @Version 1.0
 * @DESCRIPTION 司机车辆管理业务逻辑层
 */
@Service
public class CarAndCarTypeAndTansportUserServiceImpl implements CarAndCarTypeAndTansportUserServiceInter {
    //司机车辆管理数据访问层
    @Resource
    private CarAndCarTypeAndTansportUserMapper carAndCarTypeAndTansportUserMapper;

    /**
     *  查询所有车的详情和运输人和模糊查询并分页
     * @param tansportName 模糊查询名字
     * @param page 页码
     * @param rows 行数
     * @return
     */
    @Override
    public List<CarAndCarTypeAndTansportUserDto> queryAllCarAndCarTypeAndTansportUser(String tansportName, Integer page, Integer rows) {

        if (page != null){
            page = (page-1)*rows;
        }
        return carAndCarTypeAndTansportUserMapper.queryAllCarAndCarTypeAndTansportUser(tansportName,page,rows);
    }

    /**
     * 修改运输人状态
     * @param transportuser 运输人对象
     * @return
     */
    @Override
    public int updateTransportUserStatus(Transportuser transportuser) {
       int count= carAndCarTypeAndTansportUserMapper.updateTransportUserStatus(transportuser);
        return count;
    }

    /**
     * 新增车、运输人、车辆登记信息
     * @param car 车对象
     * @param transportuser 运输人对象
     * @param carRegister 车辆登记对象
     * @param carid 车的id
     * @param transportuserid 运输人id
     * @return
     */
    @Override
    @Transactional
    public int addCarAndTransportUserAndCarRegister(Car car, Transportuser transportuser,CarRegister carRegister,Long carid,Long transportuserid ) {
        int count=0;
        count=carAndCarTypeAndTansportUserMapper.addCar(car);
        count=carAndCarTypeAndTansportUserMapper.addTransportUser(transportuser);
        if(count>0){
            carAndCarTypeAndTansportUserMapper.addCarRegister(carRegister,car.getCarId(),transportuser.getId());
        }

        return count;
    }


    /**
     * 查询所有车型
     * @return
     */
    @Override
    public List<Cartype> queryAllCarType() {
        return carAndCarTypeAndTansportUserMapper.queryAllCarType();
    }
    /**
     * 查询所有员工
     * @return
     */
    @Override
    public List<Employee> queryAllEmployee() {
        return carAndCarTypeAndTansportUserMapper.queryAllEmployee();
    }
}
